package com.zfei.gfb.api.domain;

import java.io.Serializable;
import java.util.Objects;

/**
 * 事件元组
 *
 * @author fgh
 */
public class EventTuple implements Serializable, Comparable<EventTuple> {

    /**
     * 元素：事件ID
     */
    private String eventId = "0"; // 0代表起始值

    /**
     * 序值：事件时间
     */
    private Long eventTime = 0L; // 0代表起始值

    public EventTuple() {
    }

    public EventTuple(String eventId, Long eventTime) {
        this.eventId = eventId;
        this.eventTime = eventTime;
    }

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public Long getEventTime() {
        return eventTime;
    }

    public void setEventTime(Long eventTime) {
        this.eventTime = eventTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EventTuple that = (EventTuple) o;
        return Objects.equals(eventId, that.eventId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(eventId);
    }

    @Override
    public int compareTo(EventTuple o) {
        return compare(this, o);
    }

    public static int compare(EventTuple x, EventTuple y) {
        int value = Long.compare(x.getEventTime(), y.getEventTime());
        if (value == 0) {
            return x.getEventId().compareTo(y.getEventId());
        }
        return value;
    }
}
